<?php
class UserWeiboCommentAddAction extends UserAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	public function execute()
	{
		$this->code 	= 0;
		$weibo_id 		= (int)$this->context->post('weibo_id');
		$parent_id 		= (int)$this->context->post('parent_id');
		$is_relay 		= (int)$this->context->post('is_relay');
		$content 		= $this->context->post('content');
		if (!$content || !$weibo_id)
		{
			$this->code 	= 101;
			return;
		}
		$weiboCommentService	= new WeiboCommentService();
		$data = array(
			'content'=>$content,
			'user_id'=>$this->data['user']['id'],
			'content'=>$content,
			'weibo_id'=>$weibo_id,
		);
		if ($id = $weiboCommentService->addComment($data))
		{
			if ($is_relay){
				$weiboService	= new WeiboService();
				$userService	= new UserService();
				$weibo = $weiboService->get($weibo_id);
				if ($weibo){
					$weibo_user = $userService->get($weibo['usre_id']);
					//.'//@'.$weibo_user['username'].':'.$weibo['content']
					$data = array(
						'content'=>$content,
						'user_id'=>$this->data['user']['id'],
						'share_id'=>$weibo['share_id'],
						'parent_id'=>$weibo['id'],
					);
					$weiboService->addData($data);
				}
			}
			$this->code = 200;
			$created = Util::getBeforeTimelag(time());
			$this->data['home'] = C('LtUrl')->generate('User','Index', array('uid'=>$this->data['user']['id']));
			$this->data['logo'] = $this->data['user']['logo'];
			$this->data['username'] = $this->data['user']['username'];
			$this->data['content'] = $content;
			$this->data['created'] = $created;
			$this->data['id'] = $id;
		}
		
	}
}
